{% for nested_enum in nested_enums %}
{{ nested_enums[nested_enum] }}
{% endfor %}

{% if not name.upper_camel_case.endswith('Result') -%}
static std::unique_ptr<rpc::{{ plugin_name.lower_snake_case }}::{{ name.upper_camel_case }}> translateToRpc{{ name.upper_camel_case }}(const {{ package.lower_snake_case.split('.')[0] }}::{{ plugin_name.upper_camel_case }}::{{ name.upper_camel_case }} &{{ name.lower_snake_case }})
{
    auto rpc_obj = std::make_unique<rpc::{{ plugin_name.lower_snake_case }}::{{ name.upper_camel_case }}>();

{% for field in fields -%}
    {% if field.type_info.is_primitive %}
        {% if field.type_info.is_repeated %}
    for (const auto& elem : {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}) {
        rpc_obj->add_{{ field.name.lower_snake_case }}(elem);
    }
        {% else %}
    rpc_obj->set_{{ field.name.lower_snake_case }}({{ name.lower_snake_case }}.{{ field.name.lower_snake_case }});
        {% endif %}
    {% else %}
        {% if field.type_info.is_enum %}
            {% if field.type_info.is_repeated %}
    for (const auto& elem : {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}) {
        rpc_obj->add_{{ field.name.lower_snake_case }}(translateToRpc{{ field.type_info.inner_name }}(elem));
    }
            {% else %}
    rpc_obj->set_{{ field.name.lower_snake_case }}(translateToRpc{{ field.type_info.name }}({{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}));
            {% endif %}
        {% else %}
            {% if field.type_info.is_repeated %}
    for (const auto& elem : {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}) {
        auto* ptr = rpc_obj->add_{{ field.name.lower_snake_case }}();
        ptr->CopyFrom(*translateToRpc{{ field.type_info.inner_name }}(elem).release());
    }
            {% else %}
    rpc_obj->set_allocated_{{ field.name.lower_snake_case }}(translateToRpc{{ field.type_info.inner_name }}({{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}).release());
            {% endif %}
        {% endif %}
    {% endif -%}
{%- endfor %}

    return rpc_obj;
}

static {{ package.lower_snake_case.split('.')[0] }}::{{ plugin_name.upper_camel_case }}::{{ name.upper_camel_case }} translateFromRpc{{ name.upper_camel_case }}(const rpc::{{ plugin_name.lower_snake_case }}::{{ name.upper_camel_case }}& {{ name.lower_snake_case }})
{
    {{ package.lower_snake_case.split('.')[0] }}::{{ plugin_name.upper_camel_case }}::{{ name.upper_camel_case }} obj;

{% for field in fields -%}
    {% if field.type_info.is_primitive %}
        {% if field.type_info.is_repeated %}
            for (const auto& elem : {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}()) {
                obj.{{ field.name.lower_snake_case }}.push_back(elem);
            }
        {% else %}
    obj.{{ field.name.lower_snake_case }} = {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}();
        {% endif %}
    {% else %}
        {% if field.type_info.is_repeated %}
            for (const auto& elem : {{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}()) {
                obj.{{ field.name.lower_snake_case }}.push_back(translateFromRpc{{ field.type_info.inner_name }}(static_cast<mavsdk::rpc::{{ plugin_name.lower_snake_case }}::{{ field.type_info.inner_name }}>(elem)));
            }
        {% else %}
    obj.{{ field.name.lower_snake_case }} = translateFromRpc{% if field.parent_struct %}{{ field.parent_struct.name.upper_camel_case }}{% endif%}{{ field.type_info.name }}({{ name.lower_snake_case }}.{{ field.name.lower_snake_case }}());
        {% endif %}
    {% endif %}
{%- endfor %}
    return obj;
}

{% endif %}
